﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace bookssystem
{
    public partial class LoadingInterface : Form
    {
        private bool isAdding;
        private int dotCount;
        int StartPos = 0;
        public LoadingInterface()
        {
            InitializeComponent();
            InitOnLoad();
            dotCount = 0;
            isAdding = true;
        }

        private void InitOnLoad()
        {
            timer1_Tick(this, EventArgs.Empty);// 这里的this现在的指向是当前的LoadingInterface class对象
            //  EventArgs.Empty 表示没有任何的实参
        }
        /// <summary>
        /// 进度条跳转登陆界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            Dynamic_Point_Loading_Effect();
            StartPos = (StartPos != 100) ? (StartPos += 1) : StartPos;
            ProgressBar.Value = StartPos;
            Loading_Progress.Text = $"{ProgressBar.Value.ToString()}%";
            if (ProgressBar.Value == 100)
            {
                // timer1.Enabled = false;
                timer1.Stop();
                ProgressBar.Value = 0;
                this.Hide();
                Login login = new Login();
                login.Show();
            }
        }
        /// <summary>
        /// 动态点加载效果
        /// </summary>
        private void Dynamic_Point_Loading_Effect()
        {
            if (isAdding)
            {
                if (dotCount < 6)
                {
                    To_Load.Text += ".";
                    dotCount++;
                }
                else
                {
                    isAdding = false;

                }
            }
            else
            {
                if (dotCount >= 6)  // 如果还有点
                {
                    To_Load.Text = To_Load.Text.Substring(0, To_Load.Text.Length - 6);  // 去掉一个点
                    dotCount = 0;  // 点的数量减 1
                }
                else
                {
                    isAdding = true;  // 点消失完毕，切换为点增加状态
                }

            }
        }
    }
}
